;(function () {
  new Vue({
    el: '#processMange',
    data: {
      data: [],
      createData: []
    },
    methods: {
      newAdd () {
        this.createData.push({
          "module_code":"ZHSH",
          "config_name": "ZS_PROCESS_MANAGER",
          "parent_code": "#",
          "value": ''
        })
      },
      newPost (i) {
        hlhttp.post({
          url: 'configure/merchant_process',
          data: {
            "module_code": "ZHSH",
            "config_name": "ZS_PROCESS_MANAGER",
            "parent_code": "#",
            "value": this.createData[i].value
          },
          success: () => {
            hl.toast('创建成功')
            this.createData.splice(i, 1)
            this.getData()
          }
        })
      },
      newPutFlag (i) {
        this.data[i].flag = true;
      },
      newPut (i) {
        hlhttp.put({
          url: 'configure/merchant_process',
          data: {
            "module_code":"ZHSH",
            "config_name":"ZS_PROCESS_MANAGER",
            "dict_code": this.data[i].dictCode,
            "value": this.data[i].dictName
          },
          success: () => {
            hl.toast('编辑成功')
            this.data[i].flag = false;
          }
        })
      },
      deldict (i) {
        hlhttp.delete({
          url: 'configure/merchant_process?module_code=ZHSH&config_name=ZS_PROCESS_MANAGER&dict_code='+this.data[i].dictCode,
          success: () => {
            hl.toast('删除成功')
            this.getData()
          }
        })
      },
      enabledict (i) {
        hlhttp.put({
          url: 'configure/merchant_process/_enable',
          data: {
            "module_code":"ZHSH",
            "config_name":"ZS_PROCESS_MANAGER",
            "dict_code": this.data[i].dictCode
          },
          success: () => {
            hl.toast('启用成功')
            this.getData()
          }
        })
      },
      disabledict (i) {
        hlhttp.put({
          url: 'configure/merchant_process/_disable',
          data: {
            "module_code":"ZHSH",
            "config_name":"ZS_PROCESS_MANAGER",
            "dict_code": this.data[i].dictCode
          },
          success: () => {
            hl.toast('停用成功')
            this.getData()
          }
        })
      },
      removeDom (i) {
        this.createData.splice(i, 1)
      },
      getData () {
        hlhttp.get({
          url: 'configure/dict',
          data: {module_code: 'ZHSH', config_name: 'ZS_PROCESS_MANAGER'},
          success: res => {
            res.map(item => {
              item.flag = false;
            })
            this.data = res;
          }
        })
      }
    },
    mounted () {
      this.getData()
    }
  })
} ())
